This is a simple static R markdown document with an interactive plot.
We begin by importing some ETF price data that was sourced from Yahoo
Finance. We do this by using readr::read_csv().
df <- read_csv("prices.csv", show_col_types = FALSE)
df
## # A tibble: 5,040 × 8
## date symbol open high low close volume adj_close
## <date> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2017-06-19 DIA 214. 215. 214. 215. 2103300 194.
## 2 2017-06-20 DIA 215. 215. 214. 214. 1762100 194.
## 3 2017-06-21 DIA 215. 215. 214. 214. 2129400 194.
## 4 2017-06-22 DIA 214. 214. 214. 214. 2697100 193.
## 5 2017-06-23 DIA 213. 214. 213. 214. 1346800 193.
## 6 2017-06-26 DIA 214. 215. 214. 214. 1940400 194.
## 7 2017-06-27 DIA 214. 214. 213. 213. 1981600 193.
## 8 2017-06-28 DIA 213. 215. 213. 214. 4693700 194.
## 9 2017-06-29 DIA 215. 215. 212. 213. 4372600 192.
## 10 2017-06-30 DIA 213. 214. 213. 213. 2216600 193.
## # … with 5,030 more rows
Next, we create an interactive plot of the data using the
ggplot package along with the plotly
package.
plot <-
df %>%
ggplot(mapping = aes(x = date, y = adj_close, color = symbol)) +
geom_line() +
ggtitle("ETF Prices") +
xlab("date") +
ylab("adjusted close")
plot %>% ggplotly()